﻿using System;
using Cesave.Domain.PermisosModule.Entities;
using Cesave.Infrastructure.CrossCutting.Logging;
using Cesave.Infrastructure.CrossCutting.IoC;
using Cesave.DistributedServices.Core.ErrorHandlers;
using Cesave.DistributedServices.PermisosModule.Resources;
using System.ServiceModel;
using Cesave.Domain.PermisosModule.Contracts.DistritosPersonal;

namespace Cesave.DistributedServices.PermisosModule
{
	public partial class PermisosModuleService
	{
		#region IPermisosModuleService Members

		/// <summary>
		/// 
		/// </summary>
		/// <param name="distritoGuid"></param>
		/// <param name="cicloGuid"></param>
		/// <returns></returns>
		public DistritoPersonal FindDistritoPersonalByDistritoAndCiclo(Guid distritoGuid, Guid cicloGuid)
		{
			try
			{
				IDistritoPersonalService distritoPersonalService = IoCFactory.Resolve<IDistritoPersonalService>();
				return distritoPersonalService.FindDistritoPersonalByDistritoAndCiclo(distritoGuid, cicloGuid);
			}
			catch (ArgumentException ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(Messages.exception_InvalidArguments);
				throw new FaultException<ServiceError>(detail);
			}
			catch (InvalidOperationException ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(Messages.exception_InvalidArguments);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="distritoPersonal"></param>
		public void AddDistritoPersonal(DistritoPersonal distritoPersonal)
		{
			try
			{
				IDistritoPersonalService distritoPersonalService = IoCFactory.Resolve<IDistritoPersonalService>();
				distritoPersonalService.AddDistritoPersonal(distritoPersonal);
			}
			catch (ArgumentException ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(Messages.exception_InvalidArguments);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="distritoPersonal"></param>
		public void ChangeDistritoPersonal(DistritoPersonal distritoPersonal)
		{
			try
			{
				IDistritoPersonalService distritoPersonalService = IoCFactory.Resolve<IDistritoPersonalService>();
				distritoPersonalService.ChangeDistritoPersonal(distritoPersonal);
			}
			catch (ArgumentException ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(Messages.exception_InvalidArguments);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="distritoPersonal"></param>
		public void DeleteDistritoPersonal(DistritoPersonal distritoPersonal)
		{
			try
			{
				IDistritoPersonalService distritoPersonalService = IoCFactory.Resolve<IDistritoPersonalService>();
				distritoPersonalService.DeleteDistritoPersonal(distritoPersonal);
			}
			catch (ArgumentException ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(Messages.exception_InvalidArguments);
				throw new FaultException<ServiceError>(detail);
			}
		}

		#endregion
	}
}
